<?php

namespace App\Repositories\Eloquent\Biz;


use Illuminate\Container\Container as App;
use App\Repositories\Eloquent\Repository;
use Illuminate\Support\Facades\Auth;
use DB;

class SummaryRepository extends Repository
{

    function model()
    {
        return 'App\Models\Biz\Summary';
    }
    
    /**
     * 汇总表更新
     * @param [type] $user  [description]
     * @param [integer] $type 
     * 1,2:用户和志愿者签到记积分
     * 3:用户奖励记积分
     * 4:借阅数更新
     * 5:还书数更新
     * 9:交易后更新余额
     * @param [type] $point [description]
     */
    public function set($user, $type, $point = null)
    {
        switch ($type) {
            case 3:
                ++$user->summary->awards;
                $user->summary->points = $point;
                break;
            case 4:
                ++$user->summary->borrows;
                break;
            case 5:
                ++$user->summary->returns;
                break;
            case 9:
                $user->summary->points = $point;
                break;
            default:
            	++$user->summary->signs;
                $user->summary->points = $point;
                break;
        }
        $user->summary->updated_at = time();
        $user->summary->update();

    }
 

}